package yl.hs.bmipfull.service.salemanage.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import yl.hs.bmipfull.daos.salemanage.IContractTransInfoDao;
import yl.hs.bmipfull.pojo.salemanage.ContractTransInfoEntity;
import yl.hs.bmipfull.service.salemanage.IContractTransInfoService;
import yl.hs.bmipfull.utils.DataState;
import yl.hs.bmipfull.utils.Tl;
import yl.hs.bmipfull.utils.datastate.ActionType;
import yl.hs.bmipfull.viewmodels.PageQuery;

import java.util.List;
import java.util.Map;

/**
 * 作用:  销售合同运输信息服务层接口实现<br/>
 * 创建时间: 2021年05月19日 18时23分22秒 <br/>
 *
 * @author 谢东
 */
@Service
public class ContractTransInfoServiceImpl extends SaleBaseService implements IContractTransInfoService {

    @Autowired
    IContractTransInfoDao dao;

    @Override
    public List<ContractTransInfoEntity> queryList(PageQuery pageQuery) throws Exception {
        pageQuery.checkSortSides(ContractTransInfoEntity.class);
        return dao.queryList(pageQuery.getQuery());
    }


    @Override
    public ContractTransInfoEntity findBySn(String sn) {
        return dao.findBySN(sn);
    }

    @Transactional
    public Integer saveContractTransInfo(Map<String, Object> model, String sn) throws Exception {
        Integer result = 0;
        ContractTransInfoEntity entity = new ContractTransInfoEntity();
        if (Tl.isEmpty(sn)) {
            //执行保存

            Tl.getChangeLog(entity, model);
            entity.setPYFieldValue();
            entity.setSn(queryNewSN(ContractTransInfoEntity.class));
            result = dao.insertNew(entity);
            if (result > 0) {
                writeLog(ActionType.CREATE, entity.getSn(), "插入销售合同运输信息信息", Tl.toJson(entity), ContractTransInfoEntity.class);
            }

        } else {
            //执行修改
            entity = findBySn(sn);
            Tl.getChangeLog(entity, model);
            entity.setPYFieldValue();
            result = dao.update(entity);
            if (result > 0) {
                writeLog(ActionType.UPDATE, sn, "更新销售合同运输信息信息", Tl.toJson(entity), ContractTransInfoEntity.class);
            }
        }

        return result;
    }

    @Transactional
    public Integer delete(String[] sn) {

        return 0;
    }
}